#!/usr/bin/env python
# encoding: utf-8
"""
@Author: Beam
@Mail:506556658@qq.com
@file: redis-hash操作.py
@time: 2017/5/24 10:26
"""

import redis

pool = redis.ConnectionPool(host='192.168.6.248',port=63780,db=6,password='liang123456')  #连接池方式连接,用第6这个库
r = redis.Redis(connection_pool=pool)     #建立redis连接

# r.hset('info','name','Beam')
# r.hset('info','age','22')
# r.hset('info','id','001')
# print(r.hget('info','name'))

r.hmset('info2',{'name':'mity','age':22,'sex':'girl'})
# print(r.hmget('info2','age','sex'))  #获取info2这个name的某些key的值
# print(r.hgetall('info2'))     #获取info2这个name对应hash的所有key

# print(r.hlen('info2'))

# print(r.hkeys('info2'))

# print(r.hvals('info2'))

# print(r.hexists('info','name'))
# print(r.hexists('info','xxxxx'))

# r.hdel('info2','name')

# print(r.hincrby('info2','sid',1))

# print(r.hincrbyfloat('info2','fid',2.2))

for i in r.hscan_iter('info2'):
    print(i)
